import sys
sys.path.append('../utils/')
sys.path.append('./utils/')

from mysql_connector import Connector

Table_sql = """
    DROP TABLE IF EXISTS saas_table;
    CREATE TABLE saas_table(
        tableId INTEGER PRIMARY KEY,
        tableName VARCHAR(50),
        tenantId INTEGER
    );
"""

Field_sql = """
    DROP TABLE IF EXISTS saas_field;
    CREATE TABLE saas_field(
        fieldId INTEGER PRIMARY KEY,
        dataType VARCHAR(50),
        fieldName VARCHAR(50),
        tableId INTEGER,
        fieldNum INTEGER,
        tenantId INTEGER,
        isIndexed BOOL
    );
"""

Data_sql = """
    DROP TABLE IF EXISTS saas_data;
    CREATE TABLE saas_data(
        Id INTEGER AUTO_INCREMENT,
        tableId INTEGER,
        tenantId INTEGER,
        naturalName VARCHAR(100),"""

for i in range(1, 51):
    Data_sql += """
        value%d VARCHAR(500),""" % i
Data_sql += """
        PRIMARY KEY(Id)
    );"""

def create_saas_db():
    conn = Connector()
    conn.connect()

    conn.execute(Table_sql)
    conn.execute(Field_sql)
    conn.execute(Data_sql)

    conn.close()

    print("创建universal table成功!")